﻿using Interfaces.Library;
using Interfaces.Model;
using Interfaces.ViewModels;
using Model;
using Models;
using Services;

namespace ViewModels
{
    public class WorkPieceDatacapture_RealTime : IWorkPieceDataCaptureViewModel
    {
        private readonly AppDbContext _appDbContext;
        #region 全局变量与枚举
        WorkPieceDataCaptureHelper Library;     //负责从PLC读数据的类
        public tb_WorkPieceDataCapture_Realtime dataModel_Newest;  //最新采购来的数据的缓存
        public tb_WorkPieceDataCapture_Realtime dataModel_Search;  //点击列表查看详情的缓存
        public List<tb_WorkPieceDataCapture_Realtime> list_History; //最近采集的历史
        WorkPieceDataCaptureService service;    //操作数据库等的服务 
        public ProduceSummary dataModel_Summary;    //呈现统计的实体类
        #endregion
        #region 事件
        /// <summary>
        /// 构造函数
        /// </summary>
        public WorkPieceDatacapture_RealTime(AppDbContext context)
        {
            this._appDbContext = context;
            FuncResult<string> result = (FuncResult<string>)this.initialize();
        }
        //析构函数
        ~WorkPieceDatacapture_RealTime()
        {

        }
        /// <summary>
        /// 类的初始化
        /// </summary>
        /// <returns></returns>
        public IFuncResult<string> initialize()
        {
            var result = new FuncResult<string>();
            try
            {
                service = new WorkPieceDataCaptureService(this._appDbContext);
                Library = new WorkPieceDataCaptureHelper();
                dataModel_Newest = new tb_WorkPieceDataCapture_Realtime();
                dataModel_Search = new tb_WorkPieceDataCapture_Realtime();
                dataModel_Summary = new ProduceSummary();
                result.bSuccess = true;
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }
            return result;
        }

        public void ProduceRecordselected(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
        #endregion
        #region 方法

        #endregion
    }
}
